﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using FazaDemo.ViewModels;
using FazaDemo.BL.Domain;
using FazaDemo.BL.SubDomains;
using FazaDemo.PL.Mapping;
using FazaDemoSolution.BL.Domain.AbstractCore;
using FazaDemo.Data;
using AutoMapper;

namespace FazaDemo.WebSiteMvc
{
    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            Mapper.CreateMap<char?, IEnumerable<SelectListItem>>().ConvertUsing<CharEnumSelectListItemsConverter>();
            Mapper.CreateMap<NavCondElement, NavElementViewModel>()
                .ForMember(m => m.NavDropItems, e => e.MapFrom(src => src.FieldDropType))
                .ForMember(m => m.SelectedItemId, e => e.Ignore())
                .ForMember(m => m.ElemEdit, e => e.Ignore());
            Mapper.CreateMap<NavigatorCondition, NavPageViewModel>()
                .ForMember(m => m.NavArea, c => c.MapFrom(src => src.CondElements))
                .ForMember(m => m.SelectedKindId, c => c.Ignore());
            Mapper.CreateMap<SuppleInfoEntity, InfoEntity>()
               .Include<LiteSuppleInfoEntity, LiteInfoEntity>();
            Mapper.CreateMap<LiteSuppleInfoEntity, LiteInfoEntity>()
                .ForMember(i => i.Name, s => s.MapFrom(src => src.NM));
            //Mapper.CreateMap<TS_RAYON, District>()
            //    .ForSourceMember(r => r.NM_ALT, d => d.Ignore())
            //    .ForSourceMember(r => r.TS_DISTRICT, d => d.Ignore());
            //Mapper.CreateMap<TS_DISTRICT, Place>()
            //    .ForMember(p => p.DistrictName, d => d.MapFrom(src => src.RayonID))
            //    .ForMember(p => p.PrintAllStreets, d => d.MapFrom(src => src.IsVirtual))
            //    .ForSourceMember(d => d.NM_ALT, p => p.Ignore())
            //    .ForSourceMember(d => d.NM_SOC, p => p.Ignore())
            //    .ForSourceMember(d => d.SobesID, p => p.Ignore());
            Mapper.CreateMap<TS_STREET, Street>()
                .ForMember(s => s.Id, t => t.MapFrom(src => src.ID))
                .ForMember(s => s.DistrictId, t => t.MapFrom(src => src.DISTRICT_ID))
                .ForMember(s => s.Name, t => t.MapFrom(src => src.NM))
                .ForMember(s => s.AltName, t => t.MapFrom(src => src.NM_ALT))
                .ForMember(s => s.SocName, t => t.MapFrom(src => src.NM_SOC))
                .ForMember(s => s.IsVirtual, t => t.MapFrom(src => src.IS_VIRTUAL))
                .ForSourceMember(t => t.CREATED, s => s.Ignore())
                .ForSourceMember(t => t.UPDATED, s => s.Ignore())
                .ForSourceMember(t => t.USR, s => s.Ignore());
            Mapper.CreateMap<InfoEntity, SuppleViewModel>()
                .Include<LiteInfoEntity, LiteSuppleViewModel>();
            Mapper.CreateMap<LiteInfoEntity, LiteSuppleViewModel>()
                .ForMember(m => m.ListId, e => e.Ignore())
                .Include<District, DistrictViewModel>()
                .Include<Place, PlaceViewModel>();
            Mapper.CreateMap<District, DistrictViewModel>();
            Mapper.CreateMap<Place, PlaceViewModel>();
            Mapper.AssertConfigurationIsValid();
        }
    }
}
